#ifndef __LISTVIEW__
#define __LISTVIEW__

#include <stdio.h>
#include <stdlib.h>

#include <config.h>
#include <types.h>
#include <event.h>
#include <gobjs.h>
#include <page.h>
#include <linux_list.h>
#include <resources.h>

typedef GOBJ* LV_ROW;
typedef u32 LV_ROW_ID;

typedef struct listview {
    int              x,y;
    int              width;
    int              height;
    int              items;
    u32              properties;
#define LV_PROPS_ROW_UNISEL   0
#define LV_PROPS_ROW_MULTISEL 1
    int              rows_on_view;          /* total number of rows on list of view */
    int              rows_current;          /* number of rows currently on list of view */
    int              rows_total;            /* total number of rows */
    LV_ROW_ID        first_row_on_list;
    LV_ROW_ID        row_id_count;          /* counter for rows, starting from 1 */
    LV_ROW           *title;
    LV_ROW           **rows;
    COLOR            *bg_color;
    COLOR            *unsel_color;
    COLOR            *sel_color;
    GOBJ             *background;
    GOBJ             *next;
    GOBJ             *prev;
    PAGE             *page;
    void             *row_selected;
    void             (*onRowPress)(void *arg);
    struct list_head row_list;
} ListView;

typedef struct row_list_node {
    LV_ROW_ID        row_id;
    s32              row_id_on_view;
    unicode_t        **row_text;
    BOOLEAN          selected;
    struct list_head list;
} RowListNode;

typedef struct listview_priv_data {
    ListView        *lv;
    RowListNode     *row_data;
} LVPrivData;

ListView *ListView_Create(int x, int y, int width, int height, int items);
int ListView_SetRowTitles(ListView *lv, unicode_t *title_text[], int title_width[], int size);
LV_ROW_ID ListView_AddRows(ListView *lv, unicode_t *row_text[]);
int ListView_RemoveRow(ListView *lv, LV_ROW_ID row_id);
int ListView_RemoveSelectRow(ListView *lv);
int ListView_AddtoPage(PAGE *p, ListView *lv);
int ListView_Show(ListView *lv);
int ListView_UpdateAll(ListView *lv);
int ListView_UpdateRow(ListView *lv, LV_ROW_ID row_id, unicode_t *row_text[]);
inline void ListView_SetStartRow(ListView *lv, LV_ROW_ID row_id);
void __RowSetSelect(ListView *lv, RowListNode *row_data, BOOLEAN selected);

#endif
